//
//  RecorderViewController.m
//  MooreDoll
//
//  Created by Orange on 2014/12/26.
//  Copyright (c) 2014年 Tank. All rights reserved.
//
#define NotificationDefault  [NSNotificationCenter defaultCenter]

#import "RecorderViewController.h"
#import "RecorderView.h"
#import "AudioObject.h"
@interface RecorderViewController ()<RecorderViewDelegate,AudioObjectDelegate>
@property (nonatomic,strong) AudioObject *audioObject ;
@end

@implementation RecorderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _audioObject = [AudioObject sharedManager];
    [_audioObject setDelegate: self ];
}

- (void)viewWillDisappear:(BOOL)animated {
    [_audioObject audioObjectTimeStop];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark - RecorderViewDelegate
- (void) recorderViewDrawRect {
    [_audioObject audioObjectDrawRect];
}
- (void) recorderViewAgainRecrder {
    [_audioObject audioObjectAgainRecrderCompletionHandler:^(BOOL success) {
        [(RecorderView *) self.view audioRecording: success];
    }];
}
- (void) recorderViewSaveRecorder {
    [_audioObject audioObjectSaveRecorderCompletionHandler:^(NSString * filePath){
        if (filePath) {
            if (_delegate && [_delegate respondsToSelector: @selector(recorderViewControllerFilePath:)]) {
                [_delegate recorderViewControllerFilePath: filePath];
            }
        }
    } ];
    [self.navigationController popViewControllerAnimated: YES];
}
- (void) recorderViewAudioStart {
    [_audioObject audioObjectAudioStartCompletionHandler:^(BOOL success) {
        [(RecorderView *) self.view audioRecording: success];
    }];
}
- (void) recorderViewAudioPlay {
    [_audioObject audioObjectAudioPlayCompletionHandler:^(BOOL success) {
        [(RecorderView *) self.view audioPlaying: success];

    }];
}
- (void) recorderViewAudioPause {
    [_audioObject audioObjectAudioPauseCompletionHandler:^(BOOL success) {
        [(RecorderView *) self.view audioPlaying: success];

    }];
}
- (void) recorderViewAudioStop {
    [_audioObject audioObjectAudioStopCompletionHandler:^(BOOL success) {
        [(RecorderView *) self.view audioPlaying: success];
    }];
}
#pragma mark - AudioObjectDelegate
- (void)audioObjectTimeText:(NSString *)text {
    [(RecorderView *) self.view labelTimeText: text];
}
- (void)audioObjectPlayFinish {
    [(RecorderView *) self.view playFinish];
}

@end
